/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.shop.service;

import java.util.ArrayList;
import java.util.List;

import com.thinkgem.jeesite.common.service.TreeService;
import com.thinkgem.jeesite.modules.sys.entity.Office;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.shop.entity.BusinessCategory;
import com.thinkgem.jeesite.modules.shop.dao.BusinessCategoryDao;

/**
 * 商品分类Service
 * @author 开发者
 * @version 2016-07-06
 */
@Service
@Transactional(readOnly = true)
public class BusinessCategoryService extends TreeService<BusinessCategoryDao,BusinessCategory> {

    @Autowired
    private BusinessCategoryDao businessCategoryDao;

    private BusinessCategory entity = new BusinessCategory();

	public BusinessCategory get(String id) {
		return super.get(id);
	}
    @Transactional(readOnly = true)
//	public List<BusinessCategory> findList(BusinessCategory businessCategory) {
    public List<BusinessCategory> findList(BusinessCategory businessCategory,boolean e){
            if(businessCategory != null){
                businessCategory.setParentIds(businessCategory.getParentIds()+"%");
                return dao.findByParentIdsLike(businessCategory);
            }
            return  new ArrayList<BusinessCategory>();
     }

    public List<BusinessCategory> findList(BusinessCategory businessCategory){
        return dao.findList(businessCategory);
    }
//    public List<BusinessCategory> findList(Boolean isAll){
//        if (isAll != null && isAll){
//            return UserUtils.getOfficeAllList();
//        }else{
//            return UserUtils.getOfficeList();
//        }
//    }

	
	public Page<BusinessCategory> findPage(Page<BusinessCategory> page, BusinessCategory businessCategory) {
		return super.findPage(page, businessCategory);
	}
	
	@Transactional(readOnly = false)
	public void save(BusinessCategory businessCategory) {
		super.save(businessCategory);
	}
	
	@Transactional(readOnly = false)
	public void delete(BusinessCategory businessCategory) {
		super.delete(businessCategory);
	}

    public List<BusinessCategory> findByParentId(String parentId){
        BusinessCategory parent = new BusinessCategory();
        parent.setId(parentId);
        entity.setParent(parent);
        return businessCategoryDao.findByParentId(entity);
    }
	
}